package httpClientUtil;

import java.util.*;


import com.alibaba.fastjson.JSONObject;
import org.apache.http.Header;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

public class Test {

    @Autowired
    HttpUtil httpUtil;


    @ResponseBody
    @RequestMapping(value = "/login", method = {RequestMethod.POST})
    public void login(String code) throws Exception {
        long timeMillis = System.currentTimeMillis();

        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        System.out.println("uuid:" + uuid);

        List<NameValuePair> params = new ArrayList<>();
        //参数
        params.add(new BasicNameValuePair("timestamp", String.valueOf(timeMillis)));
        params.add(new BasicNameValuePair("signature", ""));
        params.add(new BasicNameValuePair("devID", ""));
        params.add(new BasicNameValuePair("merchantsID", ""));
        params.add(new BasicNameValuePair("version", "2.0"));
        params.add(new BasicNameValuePair("requestBody", ""));

        //请求头
        Header[] headers = {
                new BasicHeader("Content-Type", "application/x-www-form-urlencoded"),
                new BasicHeader("traceID", uuid),
                new BasicHeader("groupID", ""),
                new BasicHeader("shopID", "")
        };
        JSONObject jsonStr = httpUtil.postToJSONObj("https://open-test.yazhou-bay.com/tp/cert/oauth/token", params, headers);
        System.out.println("请求结果：" + jsonStr);
    }



}
